from google.appengine.ext import webapp
from google.appengine.ext.webapp import util

class SsqHandler(webapp.RequestHandler):
    def get(self):
#        self.response.out.write('Hello world!')

        # http://paipai.500wan.com/static/info/kaijiang/xml/index.xml

        f = open('ssqHisData.lex')
        sum_reds = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0]
        sum_blue = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        for l in f:
            l = l.split('\t')
            ll = l[1].split('|')
            reds = ll[0].split(',')
            blue = ll[1].replace('\n', '')
            for red in reds:
                sum_reds[int(red)-1] += 1
            sum_blue[int(blue)-1] += 1

        #sum_reds.sort()
        #sum_blue.sort()
        #print sum_reds
        #print sum_blue

        magic_reds = [0, 0, 0, 0, 0, 0]
        sum_reds_temp = sum_reds[:]
        for i in range(6):
            magic_reds[i] = sum_reds_temp.index(min(sum_reds_temp)) + 1
            #print 'magic_reds[%d] =' % (i + 1), magic_reds[i]
            #print '%d' % magic_reds[i],
            self.response.out.write('%d ' % magic_reds[i])
            sum_reds_temp[magic_reds[i] - 1] = 999

        magic_blue = sum_blue.index(min(sum_blue)) + 1
        #print 'magic_blue =', magic_blue
        #print '[%d]' % magic_blue
        self.response.out.write('[%d]' % magic_blue)

def main():
    application = webapp.WSGIApplication([('/ssq', SsqHandler)],
                                         debug=True)
    util.run_wsgi_app(application)

if __name__ == '__main__':
    main()

